import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		shopBagList: []
		//公共的变量，这里的变量不能随便修改，只能通过触发mutations的方法才能改变
	},
	mutations: {
		//相当于同步的操作
		addList(state, value) {
			let dd = state.shopBagList.findIndex(item => {
				return item.con.item_id == value.con.item_id
			})
			value["con"]["num"] = value.count
			console.log(value)
			if (dd == -1) {
				state.shopBagList.push(value)
			} else {
				state.shopBagList[dd].count += value.count
				state.shopBagList[dd]["con"]["num"] = state.shopBagList[dd]["count"]
			}

			console.log(state.shopBagList[dd])
		}
	},
	actions: {
		//相当于异步的操作,不能直接改变state的值，只能通过触发mutations的方法才能改变
	},
	getters: {}
})
export default store